package com.example.module_motorcircle.detail.repository

import com.example.lib_net.api.Api
import com.example.module_motorcircle.detail.model.PostCommentRequestModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn
import javax.inject.Inject

/**
 * @author yaotianxue
 * @description
 * @date 2025/2/14
 */
class PostDetailRepository @Inject constructor() {

    @Inject
    lateinit var api: Api


    /**
     * 帖子详情
     */
    fun postDetail(postsId:String) = flow {
        emit(api.postDetail(postsId))
    }.flowOn(Dispatchers.IO)
    /**
     * 帖子售后信息
     */
    fun postAfterSale(postsId:String, pageNum:Int = 1, pageSize:Int = 10) = flow {
        emit(api.postAfterSale(postsId, pageNum, pageSize))
    }.flowOn(Dispatchers.IO)
    /**
     * 获得帖子评论
     */
    fun postComment(postsId:String, pageNum:Int, pageSize:Int = 10) = flow {
        emit(api.postComment(postsId, pageNum, pageSize))
    }.flowOn(Dispatchers.IO)

    /**
     * 帖子评论验证
     */
    fun postCommentValidation(postsId:String,beReplyId:String) = flow {
        val model = PostCommentRequestModel(
            postsId = postsId,
            beReplyId = beReplyId
        )
        emit(api.postCommentValidation(model.toRequestBody()))
    }.flowOn(Dispatchers.IO)
    /**
     * 帖子评论
     */
    fun postCommentSave(model:PostCommentRequestModel) = flow {
        emit(api.postCommentSave(model.toRequestBody()))
    }.flowOn(Dispatchers.IO)

}